const gulp = require('gulp');
const through2 = require('through2');
const babel = require('gulp-babel');
const browserify = require('gulp-bro');
const {getProjectPath} = require('./lib/utils/getZonnarCfg')
var concat = require('gulp-concat');



gulp.task(
  'compile-to-browserify', done => {
    compile_to_browserify().on('finish', done);
  }
);

gulp.task(
  'compile-to-es5', done => {
    compile_to_es5()
    done();
  }
);

function compile_to_browserify(){
  gulp.src(['src/**/*js'])
  .pipe(
    through2.obj(function( file, encoding, next ){
      console.log(file,  encoding, next)
    })
  )
}
function compile_to_es5(){

  gulp.src([getProjectPath('src/*.js')])
  .pipe(babel())
  .pipe(gulp.dest('output/'))
  .pipe(browserify())
  // 没必要合并，因为会读取索引。
  .pipe(concat("bundle.js"))
  .pipe(gulp.dest('dist'))


}

gulp.task(
  'compile',
  gulp.series('compile-to-es5')
);